﻿// Write a program that compares two char arrays lexicographically (letter by letter).
using System;

class CompareTwoCharArrays
{
    static void Main()
    {
        Console.Write("Enter first word which will be converted to char Array: ");
        string firstWord = Console.ReadLine();
        // convert string to char array
        char[] firstCharArray = firstWord.ToCharArray();

        Console.Write("Enter second word which will be converted to char Array: ");
        string secondWord = Console.ReadLine();
        // convert string to char array
        char[] secondCharArray = secondWord.ToCharArray();

        int minLenght = Math.Min(firstCharArray.Length, secondCharArray.Length);
        int compare = 0;

        for (int i = 0; i < minLenght; i++)
        {
            compare = firstCharArray[i].CompareTo(secondCharArray[i]);
            if (compare != 0)
            {
                break;
            }
        }

        if (compare != 0)
        {
            printMessage(compare);
        }
        else
        {
            compare = firstCharArray.Length.CompareTo(secondCharArray.Length);
            printMessage(compare);
        }
    }

    private static void printMessage(int compare)
    {
        if (compare < 0)
        {
            Console.WriteLine("The first char array is lexicografically before the second.");
        }
        else if (compare > 0)
        {
            Console.WriteLine("The second char array is lexicografically before the first.");
        }
        else
        {
            Console.WriteLine("The arrays are equal.");
        }
    }
}